	$(function(){
		$('html,body').animate({ scrollTop: $("#mail") }, 'fast');
		$("#form-edit-submit").click(function() {
			//$("#user-register").submit();
			if(IsInputOk()){
				$("#user-register").submit();
			}
			//画面最上部移动
			$('html,body').animate({ scrollTop: $("#mail") }, 'fast');
		
		});
		
		$("#save").click(function() {
			//$("#user-register").submit();
			if(userInfoUpdateCheck()){
				$("#user-register").submit();
			}
			//画面最上部移动
			$('html,body').animate({ scrollTop: $("#mail") }, 'fast');
		
		});
		
		
		$("#confirm-submit").click(function() {
			$("#confirmed-register").submit();
		});
		
		$("#confirm-back").click(function() {
			history.back(1);
		});
	});
	
	function IsInputOk(){
		var result1 = isValidEmailAddress();
		var result2 = passWordCheck();
		var result3 = inputNullCheck("lastname","Last Name");
		var result4 = inputNullCheck("firstname","First Name");
		var result5 = inputNullCheck("affiliation","Affiliation/Employer");
		var result6 = inputNullCheck("street","Street");
		var result7 = inputNullCheck("city","City");
		var result8 = inputNullCheck("zip","Zip Code");
		var result9 = isRadioChecked("mailaddress","Mailling Addres");
		var result10 = isRadioChecked("mailmagazine","Mailmagazine");
		var result11 = isRadioChecked("mfee","Membership Fee");
			
		return result1 && result2 && result3 && result4 && result5 && result6 && result7 && result8 && result9 && result10 && result11;
	}
	
	function userInfoUpdateCheck(){
		var result1 = isValidEmailAddress();
		var result2 = passWordCheck();
		var result3 = inputNullCheck("lastname","Last Name");
		var result4 = inputNullCheck("firstname","First Name");
		var result5 = inputNullCheck("affiliation","Affiliation/Employer");
		var result6 = inputNullCheck("street","Street");
		var result7 = inputNullCheck("city","City");
		var result8 = inputNullCheck("zip","Zip Code");
		var result9 = isRadioChecked("mailaddress","Mailling Addres");
		var result10 = isRadioChecked("mailmagazine","Mailmagazine");
		var result11 = isRadioChecked("mfee","Membership Fee");
		
		var result12 = inputNullCheck("endDate","End Date");
		return result1 && result2 && result3 && result4 && result5 && result6 && result7 && result8 && result9 && result10 && result11 && result12;
	}
		
	//email check
	function isValidEmailAddress(){
		
		//上次的信息清空
		$("#msg-for-mail").html("");
		
		var objEmail = $("#mail");
			emailVal = jQuery.trim(objEmail.val());
			
		if (emailVal == ""){
			
			$("#msg-for-mail").html("*E-mail field is required");		
	        return false;
		} 
		if(!emailVal.match(/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/g)){
			
			$("#msg-for-mail").html("*Email format is not valid");		
			return false;
		    }
		else{
		     return true;
		    }
	}
	
	//passWord check
	
	function passWordCheck(){
		//上次的信息清空
		$("#msg-for-password1").html("");
		$("#msg-for-password2").html("");
		
		
		var objPassl = $("#password1");
		var passVal1 = jQuery.trim(objPassl.val());
		
		var objPass2 = $("#password2");
		var passVal2 = jQuery.trim(objPass2.val());
		
		//空 验证
		if (passVal1 == ""  ){
			
			$("#msg-for-password1").html("*password field is required");		
	        return false;
		} 
		if (passVal2 == ""  ){
			
			$("#msg-for-password2").html("*password field is required");		
	        return false;
		} 
		// 长度 验证
		if (passVal1.length <6 ){
			
			$("#msg-for-password1").html("*Password length is not enough");		
	        return false;
		} 
		if (passVal2.length <6){
			
			$("#msg-for-password2").html("*Password length is not enough");		
	        return false;
		} 
		
		//一致性验证
		if (passVal1 != passVal2){
			$("#msg-for-password2").html("*Password not match");	
			return false;
		}
		return true;
	}
	
	// lastName名字验证
	function lastNameCheck(){
		//上次的信息清空
		$("#msg-for-edit-field-lastname-0-value").html("");
		
		var objLastName = $("#edit-field-lastname-0-value");
		var lastNameVal = jQuery.trim(objLastName.val());
		
		//空 验证
		if (lastNameVal == ""  ){
			$("#msg-for-edit-field-lastname-0-value").html("*Last Name field is required");		
	        return false;
		} 
		return true;
	}
	
	// firstName名字验证
	function firstNameCheck(){	
		//上次的信息清空
		$("#msg-for-edit-field-firstname-0-value").html("");
		
		var objFirstName = $("#edit-field-firstname-0-value");
		var firstNameVal = jQuery.trim(objFirstName.val());
		
		//空 验证
		if (firstNameVal == ""  ){
			$("#msg-for-edit-field-firstname-0-value").html("*First Name field is required");		
	        return false;
		} 
		return true;
	}	
	
	//必须输入check
	function inputNullCheck(tagId,name){
		
		var msgTagId = "#msg-for-" + tagId;
		var elementId = "#"+ tagId;
		
		//上次的信息清空
		$(msgTagId).html("");
		
		//$('#msg-for-edit-field-affiliation-0-value option:selected').text();
		var inpuVal = $(elementId).val();
		
		//空 验证
		if (inpuVal == ""  ){
			$(msgTagId).html("*"+name+" field is required");		
	        return false;
		} 
		return true;
	}
	
	//radio check
	function isRadioChecked(radioName,name){
		
		var radio = "input:radio[name='"+radioName+"']:checked";
		var radioVal = $(radio).val();
		
		var msgElement = "#msg-for-"+radioName;
		$(msgElement).html("");	
				
		if(radioVal == null ){
			$(msgElement).html("*"+ name+ "shoud be checked");		
	        return false;
		}
		return true;
	}